<?php

class RegistrationView{

	private $RegisterButtonValue = "Register";
	private $wantedusername = "username";
	private $wantedpassword = "password";
	private $wantedpasswordcheck = "passwordcheck";
	private $registerbutton = "registerbutton";
	private $GoBackButtonValue = "Go Back";
	private $gobackbutton = "gobackbutton";
	private $getcontroll = "controll";
	
	const SUCCESS_NEW_USER = 1;
	const FAIL_NEW_USER = 2;
	const ERROR_SHORT_PASSWORD = 3;
	const ERROR_CHECK_FAIL = 4;
	const ERROR_SAME_USERNAME = 5;
	const ERROR_WRONG_CHARACTERS = 6;
	
	public function RegistrationForm(){
		return "<div><form method=\"post\" >
		<h3>Create New User</h3><br/>
		Username: <input type=\"text\" name=\"$this->wantedusername\" /></br>
		Password: <input type=\"password\" name=\"$this->wantedpassword\" /></br>
		Retype Password: <input type=\"password\" name=\"$this->wantedpasswordcheck\" /></br>
		<input type=\"submit\" value=\"$this->RegisterButtonValue\" name=\"$this->registerbutton\" />";
	}
	
	public function GetRegistrationCheckPassword(){
		return (trim($_POST[$this->wantedpasswordcheck]) != "" ? $_POST[$this->wantedpasswordcheck] : NULL);
	}
	public function GetRegistrationUsername(){
		return (trim($_POST[$this->wantedusername]) != "" ? $_POST[$this->wantedusername] : NULL);
	}
	
	public function GetRegistrationPassword(){
		return (trim($_POST[$this->wantedpassword]) != "" ? $_POST[$this->wantedpassword] : NULL);	
	}
	
	public function TryToRegister(){
		return (isset($_POST[$this->registerbutton]) && $_POST[$this->registerbutton] == $this->RegisterButtonValue);
	}
	public function ResetButtonClick(){
		unset($_POST[$this->registerbutton]);
	}
	
	
	public function PasswordCheck($password, $passwordcheck){
		
		if($password == $passwordcheck){
			return TRUE;
		}
		else{
			return FALSE;
		}
	}
		
	public function Messages($index){
		switch ($index) {
			case self::SUCCESS_NEW_USER:
				return "You have successfully created a new user, try by logging in!";
				break;
			case self::FAIL_NEW_USER:
				return "There was a problem creating your account, please try again!";
				break;
			case self::ERROR_SHORT_PASSWORD:
				return "</br>Your password needs to be over 6 characters long.";
				break;
			case self::ERROR_CHECK_FAIL:
				return "</br>You need to type the same password into both the password boxes.";
				break;
			case self::ERROR_SAME_USERNAME:
				return "</br>This username is already taken, try again with a different one.";
				break;
			case self::ERROR_WRONG_CHARACTERS:
				return "</br>You are using characters which is not allowed in the password.";
				break;
			default:
				return "This errormessage is not added yet.";
				break;
		}
	}
	
	
	
	
}


?>